﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SuperMarketSystem
{
    public partial class Login : Form
    {
        Trans trans;
        public Login(ref Trans trans)
        {
            InitializeComponent();
            this.trans = trans;
        }

        private void buttonLogin_Click(object sender, EventArgs e)//添加登录按钮单击事件
        {
            SqlConnection loginConnection = MySqlServerUtils.getMySqlServerConnection();
            String loginCommand = String.Format("select * from users where username='{0}' and password='{1}'",username.Text,password.Text);
            SqlCommand commandLogin = new SqlCommand(loginCommand, loginConnection);
            SqlDataReader logindr = commandLogin.ExecuteReader();
            if (logindr.Read())//查询是否有对应的用户名密码
            {
                MessageBox.Show("欢迎进入小型超市销售管理系统," + username.Text);
                this.trans.setUsernameTrans(username.Text);
                this.trans.setPasswordTrans(password.Text);
                this.trans.setLoginFlag(1);
                this.Close();
            }
            else
            {
                MessageBox.Show("用户名或者密码错误");
                username.Clear();
                password.Clear();
            }
            MySqlServerUtils.closeSqlServerConnection(loginConnection);
        }
    }
}
